/**
 *******************************************************************************
 * @file      led_driver.c
 * @version   V1.0.0    
 * @date      2013.05.04
 * @brief     LED driver for Taranis.	
 * @author    - Adela 
 *            - Robert Zhang <armner@gmail.com>
 *            - 
 */
#include "led_driver.h"
#include "stm32f2xx.h"


int led_open(Driver *driver)
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    /* Configure PB8 in output pushpull mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    return 0;
}
int led_write(Driver *driver, void *buffer, int len, OFFSET offset)
{
    char t_char=*((char *)buffer);
    if(t_char&1)
    {
        GPIOB->BSRRL =GPIO_Pin_8;
    }
    else
    {
        GPIOB->BSRRH =GPIO_Pin_8;
    }
    
    return len;
}

Driver led_driver=
{
    &led_open,
    &led_write,
    NULL,
    NULL,
    NULL
};
